/*
 * DProgresoGuardar.java
 *
 * Created on 15 de junio de 2007, 09:15 AM
 */

package ig.metrica.ui.escenario;

import javax.swing.JFrame;

/**
 *
 * @author  jsanchez
 */
public class DProgresoGuardar extends javax.swing.JDialog  {
    
    /** Creates new form DProgresoGuardar */
    public DProgresoGuardar(java.awt.Frame parent) {
        super(parent, true);
        initComponents();
        jProgressBar1.setIndeterminate(true);
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        java.awt.Dimension dimensionScreen = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Rectangle dimensionPantalla = getBounds();
        setLocation((dimensionScreen.width - dimensionPantalla.width) / 2, (dimensionScreen.height - dimensionPantalla.height) / 2);                
        new ManejadorIconos().start();
    }
    public void setMensaje(String mensaje){
        this.LTabla.setText(mensaje.trim());
    }
    
    public void setEscenario(String mensaje){
        this.LEscenario.setText("Finalizando "+mensaje.trim());
    }    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        IDerecho = new javax.swing.JLabel();
        IIzquierdo = new javax.swing.JLabel();
        jProgressBar1 = new javax.swing.JProgressBar();
        LTabla = new javax.swing.JLabel();
        LEscenario = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        IDerecho.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        IDerecho.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ig/util/images/a1.png"))); // NOI18N
        IDerecho.setText(org.openide.util.NbBundle.getMessage(DProgresoGuardar.class, "DProgresoGuardar.IDerecho.text")); // NOI18N
        IDerecho.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        IIzquierdo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        IIzquierdo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ig/util/images/b1.png"))); // NOI18N
        IIzquierdo.setText(org.openide.util.NbBundle.getMessage(DProgresoGuardar.class, "DProgresoGuardar.IIzquierdo.text")); // NOI18N
        IIzquierdo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jProgressBar1.setForeground(new java.awt.Color(0, 0, 204));
        jProgressBar1.setBorder(null);

        LTabla.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        LTabla.setText(org.openide.util.NbBundle.getMessage(DProgresoGuardar.class, "DProgresoGuardar.LTabla.text")); // NOI18N

        LEscenario.setText(org.openide.util.NbBundle.getMessage(DProgresoGuardar.class, "DProgresoGuardar.LEscenario.text")); // NOI18N

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(LEscenario, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(IIzquierdo)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(LTabla, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE)
                            .add(jProgressBar1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(IDerecho)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(LEscenario)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(IIzquierdo)
                        .add(IDerecho))
                    .add(layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(LTabla)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jProgressBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        
    }//GEN-LAST:event_formWindowClosing

    
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new DProgresoGuardar(new javax.swing.JFrame(), true).setVisible(true);
//            }
//        });
//    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel IDerecho;
    private javax.swing.JLabel IIzquierdo;
    private javax.swing.JLabel LEscenario;
    private javax.swing.JLabel LTabla;
    private javax.swing.JProgressBar jProgressBar1;
    // End of variables declaration//GEN-END:variables
    
    
    class ManejadorIconos extends Thread {
        private boolean seguir=true;
        public void setSeguir(boolean seguir){
            this.seguir=seguir;
        }
        int i=1;
        @Override
        public void run() {
            while(seguir){
                IDerecho.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ig/util/images/a"+(i++)+".png")));
                IIzquierdo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ig/util/images/b"+(i-1)+".png")));
                try{Thread.sleep(1000);}catch(Exception e){}
                if(i>3)
                    i=1;
            }
        }
        
    }
}
